package dk.mirasola.systemtraining.server.entity;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Parent;
import com.googlecode.objectify.annotation.Unindexed;
import dk.mirasola.systemtraining.bridgewidgets.shared.factory.BidFactory;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.Bid;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.Seat;

import javax.persistence.Id;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;

public class AutoBid {
    @Id
    Long id;

    @Parent
    Key<BiddingSet> biddingSetKey;

    @Unindexed
    Seat seat;

    @Unindexed
    int round;

    @Unindexed
    String bidStr;

    @Transient
    Bid bid;

    public AutoBid(Key<BiddingSet> biddingSetKey) {
        this.biddingSetKey = biddingSetKey;
    }

    public Long getId() {
        return id;
    }

    public Key<BiddingSet> getBiddingSetKey() {
        return biddingSetKey;
    }

    public Seat getSeat() {
        return seat;
    }

    public void setSeat(Seat seat) {
        this.seat = seat;
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        this.round = round;
    }

    public Bid getBid() {
        return bid;
    }

    public void setBid(Bid bid) {
        this.bid = bid;
    }

    @PrePersist
    void bidToString() {
        bidStr = BidFactory.bidToString(bid);
    }

    @PostLoad
    void stringToBid() {
        bid = BidFactory.stringToBid(bidStr);
    }

}
